package logic

import (
	"context"
	"doctor-medicine-system/models/mysql"
	"errors"

	"doctor-medicine-system/medrpc/internal/svc"
	"doctor-medicine-system/medrpc/medrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedListLogic {
	return &MedListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MedListLogic) MedList(in *medrpc.MedListRequest) (*medrpc.MedListResponse, error) {
	// todo: add your logic here and delete this line

	var meds []*medrpc.MedList

	meds, err := mysql.MedList(mysql.DB)
	if err != nil {
		return nil, errors.New("列表失败")
	}

	return &medrpc.MedListResponse{
		List: meds,
	}, nil
}
